package com.xiaolin.designmode.memento;

/**
 * @ClassName MementoTest
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/9
 * @Version 1.0
 */
public class MementoTest {
    public static void main(String[] args) {
        Originator originator=new Originator();
        originator.setState("第一次备忘");
        //保存状态
        Caretaker caretaker=new Caretaker();
        caretaker.setMemento(originator.createMemento());
        //误操作
        originator.setState("误操作");
        System.out.println(originator.getState());
        //回退
        originator.restoreMemento(caretaker.getMemento());
        //验证是否回退成功
        System.out.println(originator.getState());
}
}
